﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ATM;

namespace ATM
{
    public class PowerOnState : ATMState
    {
        public ATM atm;

        public PowerOnState(ATM atm)
        {
            this.atm = atm;
        }

        public void pressPowerButton()
        {
            this.atm.setState(this.atm.powerOffState);

            this.atm.switchButton.Text = "Power On";
            this.atm.powerOn = false;
            this.atm.screen.BackColor = Color.LightGray;
            this.atm.keypadScreen.BackColor = Color.LightGray;

            this.atm.oneButton.Enabled = false;
            this.atm.twoButton.Enabled = false;
            this.atm.threeButton.Enabled = false;
            this.atm.fourButton.Enabled = false;
            this.atm.fiveButton.Enabled = false;
            this.atm.sixButton.Enabled = false;
            this.atm.sevenButton.Enabled = false;
            this.atm.eightButton.Enabled = false;
            this.atm.nineButton.Enabled = false;
            this.atm.zeroButton.Enabled = false;
            this.atm.enterButton.Enabled = false;

            this.atm.screen.Text = "";
            this.atm.keypadScreen.Text = "";
            this.atm.bankDatabase.UpdateDatabase();
            this.atm.bankDatabase.CloseConnection();
        }

        public void pressTakeCashButton()
        {
            return;
        }

        public void pressInsertEnvelopButton()
        {
            return;
        }

        public void pressEnterButton()
        {
            if (this.atm.keypadScreen.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("请输入数字后按Enter键确认!");
                return;
            }

            this.atm.commandString = this.atm.keypadScreen.Text;
            this.atm.commandNumber = Convert.ToInt32(this.atm.commandString);
            this.atm.keypadScreen.Text = "";

            if (this.atm.bankDatabase.isValidAccount(this.atm.commandString))
            {
                if (this.atm.belongTo == "B" && this.atm.bankDatabase.findBankByID(this.atm.commandString) == "D")
                {
                    System.Windows.Forms.MessageBox.Show("本取款机暂不支持D银行的银行卡");
                    this.atm.setState(this.atm.powerOnState);
                    return;
                }

                this.atm.currentAccountID = this.atm.commandString;
                this.atm.setState(this.atm.checkPasswordState);
                this.atm.keypadScreen.UseSystemPasswordChar = true;
                this.atm.switchButton.Enabled = false;
                this.atm.screen.Text = "请输入密码，按Enter键结束";
            }

            else
            {
                System.Windows.Forms.MessageBox.Show("不存在此账户，请重新输入!");
                this.atm.setState(this.atm.powerOnState);
            }

            return;
        }

    }
}
